<?php
/**
 * View  LaFabbrica.org
 * 
 * @author     luigi.pastore (gigi@la-fabbrica.org)
 * @created    17-mag-2011
 * @package    LaFabbrica
 * @copyright  Copyright (c) 2011 Luigi Pastore
 */
?>
<!--<script src="http://static.flowplayer.org/js/flowplayer-3.2.6.min.js"></script>-->

<script type="text/javascript">
    //<![CDATA[
     
    $(document).ready(function() {
        var i = 1;
        
        function add(){
            i++;
            $.ajax({
                url: "/admin/ajax/get/video-preview-box/id/"+ i,
                dataType : 'html',
                  success: function(data) {
                    $('div#links-container').append(data);
                    $('input[id*="post_link'+i+'"]').focusout(focusOutFunction);
                  }
                });
        };
        
        $('button.add-link').click(function(){ 
            add();
        });        

        // Nascondiamo tutte le anteprime e il pulsante aggiungi
        $(".preview-box").not('[class*="current"]').hide();
        $('button.add-link').hide();
        
        // Applico l'evento a tutti i campi con class contentente "link"
        var focusOutFunction = function(e){

            // Ottengo l'id del link eliminando dal nome la stringa 'post_link'
            var id = $(this).attr('id').match(/post_link([0-9]+)/);
            id = id[1];

            if($("#linksForm").validate().element( $(this) )){
                // Grab video ID from the url
                var videoID = $(this).val().match(/watch\?v=(.+)+/);

                // Google
                if(videoID)
                {
                    // Carico e visualizzo l'anteprima...
                    $('#link_preview_box_'+id).show();
                    $('#link_preview_'+id)
                        .flashembed(	
                            // configuration
                            {src: 'http://www.youtube.com/v/'+videoID[1], wmode: 'transparent', menu: 'false', w3c: true}, 
                            // flashvars
                            { fs: 1, autoplay: 0, hd: 1, showinfo:0, rel:0  }
                        )                        
                }

                var videoID = $(this).val().match(/vimeo.com\/(\d{7})/);

                // Vimeo
                if(videoID)
                {
                    // Carico e visualizzo l'anteprima...
                    $('#link_preview_box_'+id).show();
                    $('#link_preview_'+id)
                        .flashembed({
                            src: "http://www.vimeo.com/moogaloop.swf", 
                            wmode: 'transparent', 
                            menu: 'false', 
                            w3c: true
                        },{ 
                            clip_id: videoID[1], 
                            server: 'vimeo.com', 
                            fullscreen: 1, 
                            autoplay: 0, 
                            how_title: 0, 
                            show_byline: 0, 
                            show_portrait: 0  }
                        )
                }

                $('button.add-link').show();
            }   
            else
            {
                $('#link_preview_box_'+id).hide();
            }
        }
        
        // Applico la funzione all'input link-url
        //$('input[class*="link-url"]').change(focusOutFunction);
        $('input[class*="link-url"]').change(focusOutFunction);

        // Lancia le anteprime e il pulsante aggiungi
        $('input[class*="link-url"]').trigger('change');
        
        $('a.del').click(function(){
            var id = $(this).attr('id').match(/post-link-([0-9]+)/);
            
            $('ul#video-preview-box-'+id[1]).remove();
        });
    });

    //]]>
</script>

<form class="fab" name="linksForm" id="linksForm" action="/admin/live/postlinks/id/<?php echo $this->data['live_id'] ?>" method="post" enctype="multipart/form-data">
<div id="content">

    <div id="summary" class="live">
        <div class="head live">
            <h2>Info Live:</h2>
        </div>
        <div class="body">
            <table cellspacing="0" class="table">
                <tbody>
                    <tr>
                        <th>Artista:</th>
                        <td>
                            <strong>
                                <?php
                                foreach( $this->live['artists']['main'] as $artist ) :
                                    $artists_list .= $artist['artist_name'] . ', ';
                                endforeach;
                                ?>
                                <?php echo substr( $artists_list, 0, -2 ); ?>
                            </strong>
                        </td>
                    </tr>
                    <?php if( count( $this->live['artists']['openingact'] ) ): ?>
                        <tr>
                            <th>Open-act:</th>
                            <td>
                                <strong>
                                    <?php
                                    $artists_list = null;
                                    foreach( $this->live['artists']['openingact'] as $artist ) :
                                        $artists_list .= $artist['artist_name'] . ', ';
                                    endforeach;
                                    ?>
                                    <?php echo substr( $artists_list, 0, -2 ); ?>				
                                </strong>
                            </td>
                        </tr>			
                    <?php endif; ?>
                    <tr>
                        <th>Location:</th>
                        <td><strong><?php echo $this->live['location']['location_name'] ?>, <?php echo $this->live['location']['location_city'] ?> (<?php echo $this->province[$this->live['location']['location_province_id']]['province_short_name'] ?>)</strong></td>
                    </tr>
                    <tr>
                        <th>Quando:</th>
                        <td><strong><?php echo $this->days[date( 'N', mktime( $hour, $minute, $second, $this->live['live_date_m'], $this->live['live_date_d'], $this->live['live_date_y'] ) )] ?>, <?php echo $this->live['live_date_ita'] ?></strong></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

    
        <ul>
            <li class="paging-context ">
                <table class="pgStyle1 circle2" cellspacing="0">
                    <tr>
                        <td class="c">
                            <var>1</var>
                        </td>
                        <td class="t">
                            <b id="pagecircle1"><a href="/admin/live/post/id/<?php echo $this->live['live_id'] ?>">Post</a></b>
                        </td>
                        <td class="c selected">
                            <var>2</var>
                        </td>
                        <td class="t selected">
                            <b id="pagecircle2">Collegamenti</b>
                        </td>
                        <td class="c ">
                            <var>3</var>
                        </td>
                        <td class="t">
                            <b id="pagecircle2">Immagine</b>
                        </td>                        
                    </tr>
                </table>
            </li>
        </ul>
    
    <div class="help">
        <h2>Links:</h2>
        <br/>
        <div>Inserisci links</div>
    </div>   
        <ul>
            <li id="errorLi" style="<?php echo $this->errorMsg ? '' : 'display:none' ?>">
                <h3 id="errorMsgLbl">Si &egrave; verificato un problema durante l'invio del modulo.</h3>
                <p id="errorMsg">
                    Di seguito trovi evidenziati gli errori riscontrati. <?php echo $this->errorMsg['post_link'] ?>
                </p>
            </li>
        </ul>

        <div id="links-container">
            <?php 
            if( count( $this->post['post_links'] ) ):
                foreach( $this->post['post_links'] as $post_link ):
                ?>
                <ul class="video-preview-box current" id="video-preview-box-<?php echo $post_link['link_id'] ?>">
                    <li class="<?php echo $this->errorMsg['post_link'] ? 'error' : '' ?> with-preview">
                        <label class="desc <?php echo $this->errorMsg['post_link1'] ? 'error' : '' ?>">Link asd</label>
                            <div>
                                <span class="input">
                                    <input class="field text addr link-url" name="post_links[]" id="post_link<?php echo $post_link['link_id'] ?>" size="50" type="text" value="<?php echo $post_link['link_url']?>" />
                                    <label>Descrizione</label>
                                </span>

                                <span class="input">
                                    <input class="field text addr link-desc" name="post_link_desc[]" id="post_link_desc<?php echo $post_link['link_id'] ?>" size="50" type="text" value="<?php echo $this->data['post_link_desc']?>" />
                                </span>
                            </div>
                        <p class="error" style="<?php echo $this->errorMsg['post_link'] ? 'display:block' : '' ?>"><?php echo $this->errorMsg['post_link'] ?></p>
                    </li>

                    <li class="preview-box current" id="link_preview_box_<?php echo $post_link['link_id'] ?>">
                        <span>
                        <small><strong>Anteprima</strong></small>
                        </span>
                        <div id="link_preview_<?php echo $post_link['link_id'] ?>" class="link-preview"></div>
                    </li>
                    <li class="with-preview remove">
                        <span class="actions">
                            <a class="del" id="post-link-<?php echo $post_link['link_id'] ?>">Elimina</a>
                        </span>
                    </li>
                </ul>
                <?php
                endforeach;
            else:
                ?>
                <ul class="video-preview-box" id="video-preview-box-1">
                    <li class="<?php echo $this->errorMsg['post_link'] ? 'error' : '' ?> with-preview">
                        <label class="desc <?php echo $this->errorMsg['post_link1'] ? 'error' : '' ?>">Link asd</label>
                            <div>
                                <span class="input">
                                    <input class="field text addr link-url" name="post_links[]" id="post_link1" size="50" type="text" value="<?php echo $post_link['link_url']?>" />
                                    <label>Descrizione</label>
                                </span>

                                <span class="input">
                                    <input class="field text addr link-desc" name="post_link_desc[]" id="post_link_desc1" size="50" type="text" value="<?php echo $this->data['post_link_desc']?>" />
                                </span>
                            </div>
                        <p class="error" style="<?php echo $this->errorMsg['post_link'] ? 'display:block' : '' ?>"><?php echo $this->errorMsg['post_link'] ?></p>
                    </li>

                    <li class="preview-box" id="link_preview_box_1">
                        <span>
                        <small><strong>Anteprima</strong></small>
                        </span>
                        <div id="link_preview_1" class="link-preview"></div>
                    </li>
                    <li class="with-preview remove" style="display: none;">
                        <span class="actions">
                            <a class="del" id="post-link-1">Elimina</a>
                        </span>
                    </li>
                </ul>     
                <script type="text/javascript">
                //<![CDATA[

                $(document).ready(function()
                {
                    $("#link_preview_box_1").hide();
                    $("#post_link1").rules("add", {
                        url: true,
                        messages: {
                            url: "<?php echo sprintf( ERR_URL, 'Url' ) ?>"
                        }
                    });

                });

                //]]>
                </script>
                <?php
            endif;
            ?>

        </div>
        <div class="add-link-box">
            <button id="" type="button" name="salva" value="salva" class="button add-link">
                <img src="/images/admin/add-new.png" alt="" />Aggiungi Altro Collegamento
            </button>
        </div>           
        
</div>
<div id="formButtons">
    <button id="salva" type="submit" name="conferma" value="conferma" class="button positive">
        <img src="/images/admin/tick.png" alt="" />Continua
    </button>
    <button id="annulla" name="annulla" value="annulla" class="button negative">
        <img src="/images/admin/cross.png" alt="" />Annulla
    </button>
</div>
</form>
